package io.xxx.xbutler.core.event.job;

import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class CoreJobConfig {

    @Bean
    public JobDetail messagePushJobDetail() {
        return JobBuilder.newJob(MessagePushJob.class)
                .withIdentity("messagePushJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger messagePushJobTrigger(JobDetail messagePushJobDetail) {
        return TriggerBuilder.newTrigger()
                .withIdentity("messagePushJobTrigger")
                .forJob(messagePushJobDetail)
                .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(5))
                .build();
    }

    @Bean
    public JobDetail taskExecuteJobDetail() {
        return JobBuilder.newJob(TaskExecuteJob.class)
                .withIdentity("taskExecuteJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger taskExecuteJobTrigger(JobDetail taskExecuteJobDetail) {
        return TriggerBuilder.newTrigger()
                .withIdentity("taskExecuteJobTrigger")
                .forJob(taskExecuteJobDetail)
                .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(5))
                .build();
    }

    @Bean
    public JobDetail taskCheckExpireJobDetail() {
        return JobBuilder.newJob(TaskCheckExpireJob.class)
                .withIdentity("taskExecuteJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger taskCheckExpireJobTrigger(JobDetail taskCheckExpireJobDetail) {
        return TriggerBuilder.newTrigger()
                .withIdentity("taskCheckExpireJobTrigger")
                .forJob(taskCheckExpireJobDetail)
                .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(5))
                .build();
    }

    @Bean
    public JobDetail callbackDataCleanJobDetail() {
        return JobBuilder.newJob(CallbackDataCleanJob.class)
                .withIdentity("callbackDataCleanJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger callbackDataCleanJobTrigger(JobDetail callbackDataCleanJobDetail) {
        return TriggerBuilder.newTrigger()
                .withIdentity("callbackDataCleanJobTrigger")
                .forJob(callbackDataCleanJobDetail)
                .withSchedule(SimpleScheduleBuilder.repeatHourlyForever(12))
                .build();
    }
}
